//
//  InformationTableViewCell.m
//  UI_A项目
//
//  Created by dlios on 15-1-17.
//  Copyright (c) 2015年 songCheng. All rights reserved.
//

#import "InformationTableViewCell.h"

@implementation InformationTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}

- (void)createSubView
{
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 0, 200, 70)];
//    self.titleLabel.backgroundColor = [UIColor blackColor];
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    self.titleLabel.numberOfLines = 0;
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    self.nicknameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y + 80, 150, 30)];
    self.nicknameLabel.font = [UIFont systemFontOfSize:15];
    self.nicknameLabel.numberOfLines = 0;
    [self.contentView addSubview:self.nicknameLabel];
    [_nicknameLabel release];

    
    self.durationLabel = [[UILabel alloc] initWithFrame:CGRectMake(270, 100, 50, 30)];
        [self.contentView addSubview:self.durationLabel];
        self.durationLabel.font = [UIFont systemFontOfSize:12];
        [_durationLabel release];

    
    self.durationImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-shijian-2.png"]];
    self.durationImageView.frame = CGRectMake(245, 105, 20, 20);
    [self.contentView addSubview:self.durationImageView];
    [_durationImageView release];
    
    
    self.playTimesLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 100, 50, 30)];
    [self.contentView addSubview:self.playTimesLabel];
    self.playTimesLabel.font = [UIFont systemFontOfSize:12];
    [_playTimesLabel release];
    
    self.playTimesImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-iconfontbofang.png"]];
    self.playTimesImageView.frame = CGRectMake(10, 105,20, 20);
    [self.contentView addSubview:self.playTimesImageView];
    [_playTimesImageView release];
    
    self.commentsLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 100, 50, 30)];
    [self.contentView addSubview:self.commentsLabel];
    self.commentsLabel.font = [UIFont systemFontOfSize:12];
    [_commentsLabel release];
    
    self.commentsImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-iconfontpinglun-2.png"]];
    self.commentsImageView.frame =  CGRectMake(170, 106, 20, 20);
    [self.contentView addSubview:self.commentsImageView];
    [_commentsImageView release];
    
    
    self.likesLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 100, 50, 30)];
    [self.contentView addSubview:self.likesLabel];
    self.likesLabel.font = [UIFont systemFontOfSize:12];
    [_likesLabel release];

    self.likesImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-xin.png"]];
    self.likesImageView.frame = CGRectMake(100, 105, 20, 20);
    [self.contentView addSubview:self.likesImageView];
    [_likesImageView release];
    
    
    
    self.albumImageImageView = [[UIImageView alloc] initWithFrame:CGRectMake(270, 10, 100, 90)];
    self.albumImageImageView.layer.masksToBounds = YES;
    self.albumImageImageView.layer.cornerRadius = 20;
    self.albumImageImageView.layer.borderWidth = 5;
    self.albumImageImageView.layer.borderColor = [UIColor blackColor].CGColor;
    [self.contentView addSubview:self.albumImageImageView];
    [_albumImageImageView release];
    
    
    UIImage *image = [UIImage imageNamed:@"1234.jpg"];
    UIButton *pButton = [UIButton buttonWithType:UIButtonTypeCustom];
    pButton.frame = CGRectMake(10, 30, 40, 40);
    [self.contentView addSubview:pButton];
    [pButton addTarget:self action:@selector(but:) forControlEvents:UIControlEventTouchUpInside];
    [pButton setBackgroundImage:image forState:UIControlStateNormal];
    self.isSelected = NO;
    
    
    
    
    
    
    
    
//    self.playImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1234.jpg"]];
//    self.playImageView.frame = CGRectMake(10, 30, 40, 40);
//    [self.contentView addSubview:self.playImageView];
//    [_playImageView release];
//
//    
//    
//    self.stopimageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.jpg"]];
//    self.stopimageView.frame = CGRectMake(self.playImageView.frame.origin.x, self.playImageView.frame.origin.y, self.playImageView.frame.size.width, self.playImageView.frame.size.height);
//    [self.contentView addSubview:self.stopimageView];
//    [_stopimageView release];
    
    
    UIView *lastView = [[UIView alloc] initWithFrame:CGRectMake(0, 125, 375, 28)];
    lastView.alpha = 0.6;
    lastView.backgroundColor = [UIColor lightGrayColor];
    [self.contentView addSubview:lastView];
    [lastView release];
    
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    //    button.backgroundColor = [UIColor lightGrayColor];
    
    [button setTitle:@"赞" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [lastView addSubview:button];
    button.frame = CGRectMake(20, 3, 100, 20);
    self.isSelected = NO;
    
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.frame = CGRectMake(155, 3, 100, 20);
    [button1 setTitle:@"看评论" forState:UIControlStateNormal];
    [button1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button1 addTarget:self action:@selector(buttonAction1:) forControlEvents:UIControlEventTouchUpInside];
    [lastView addSubview:button1];
    
    UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-iconfontpinglun-2.png"]];
    imageV.frame = CGRectMake(150, 128, 20, 20);
    [self.contentView addSubview:imageV];
    [imageV release];
    
    
    UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    button2.frame = CGRectMake(280, 3, 100, 20);
    [button2 setTitle:@"下载" forState:UIControlStateNormal];
    [button2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [button2 addTarget:self action:@selector(buttonAction2:) forControlEvents:UIControlEventTouchUpInside];
    [lastView addSubview:button2];
    
    UIImageView *imageV1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iconfont-iconfontxiazai.png"]];
    imageV1.frame = CGRectMake(280, 128, 20, 20);
    [self.contentView addSubview:imageV1];
    [imageV1 release];
    
    
}

- (void)setModel:(ClassModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    self.titleLabel.text = model.title;
    self.nicknameLabel.text = model.nickname;
    self.playTimesLabel.text = model.playTimes;
    self.commentsLabel.text = model.comments;
    self.likesLabel.text = model.likes;
    NSURL *url = [NSURL URLWithString:model.coverLarge];
    [self.albumImageImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"d52a2834349b033b18d7c6dd16ce36d3d539bd5d.jpg"]];
    
    
    
    NSString *duration = model.duration;
    NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:[duration doubleValue]];
    //    NSLog(@"%@", date);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateFormat = @"mm:ss";
    NSString *str1 = [dateFormatter stringFromDate:date];
    self.durationLabel.text = str1;
    
}




- (void)but:(UIButton *)but
{
    if (self.isSelected == YES) {
        UIImage *image = [UIImage imageNamed:@"1234.jpg"];
        [but setBackgroundImage:image forState:UIControlStateNormal];
    }
    else if(self.isSelected == NO)
    {
        UIImage *image1 = [UIImage imageNamed:@"1.jpg"];
        [but setBackgroundImage:image1 forState:UIControlStateNormal];
    }
    
    self.isSelected = !self.isSelected;
}


- (void)buttonAction:(UIButton *)button
{
    if (self.isSelected == YES) {
        [button setTitle:@"  赞" forState:UIControlStateNormal];
    }
    else if (self.isSelected == NO)
    {
        [button setTitle:@"❤️  取消" forState:UIControlStateNormal];
    }
    self.isSelected = !self.isSelected;
    
}

- (void)buttonAction1:(UIButton *)button
{
    
}


- (void)buttonAction2:(UIButton *)button
{
    if (self.isSelected == YES) {
        
        [button setTitle:@"下载" forState:UIControlStateNormal];

    }
    else if (self.isSelected == NO)
    {
        [button setTitle:@"已下载" forState:UIControlStateNormal];
        
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"成功加载列表" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
        [UIView animateWithDuration:1.5 animations:^{
            
            [NSTimer scheduledTimerWithTimeInterval:2.0f
                                             target:self
                                           selector:@selector(timerFireMethod:)
                                           userInfo:alert
                                            repeats:YES];
            
            [alert show];
            
          
            
            
        } completion:^(BOOL finished) {
            
            [alert removeFromSuperview];
        }];

    }
    self.isSelected = !self.isSelected;
}

- (void)timerFireMethod:(NSTimer*)theTimer//弹出框
{
    UIAlertView *alert = (UIAlertView*)[theTimer userInfo];
    [alert dismissWithClickedButtonIndex:0 animated:NO];
    alert = NULL;
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
